<?php

namespace app\index\dao;

use app\common\model\AccountTokenPlan;
use ShidianUtil\Thinkphp\Dao\DaoTrait;

/**
 * AccountTokenPlanDao 数据访问对象
 * Class AccountTokenPlanDao
 * @package app\index\dao
 * @method AccountTokenPlan findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method AccountTokenPlan insertActive(array $params, array $allow_field = [])
 * @method AccountTokenPlan updateActive(AccountTokenPlan $model, array $params, array $allow_field = [])
 * @method AccountTokenPlan findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method AccountTokenPlan updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(AccountTokenPlan $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class AccountTokenPlanDao
{
    use DaoTrait;

    /**
     * @var AccountTokenPlan
     */
    private $baseModel;

    /**
     * AccountTokenPlanDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = AccountTokenPlan::class;
    }

    public function find($id)
    {
        return AccountTokenPlan::where('id', $id)
            ->order('ord', 'ASC')
            ->withAttr([
                'price' => function ($value) {
                    return number_format($value, 1, '.', '');
                }
            ])
            ->find();
    }

    public function select($planType)
    {
        return AccountTokenPlan::where('planType', $planType)
            ->where('show', 1)
            ->order('ord', 'ASC')
            ->withAttr([
                'price' => function ($value) {
                    return number_format($value, 0, '.', '');
                }
            ])
            ->select();
    }
}
